package com.ysxsoft.wdg.widget.alertview;

import android.content.Context;
import android.text.TextUtils;

import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.util.ViewUtils;


public class AlertViewFactory {
    private static volatile AlertViewFactory defaultInstance;

    private AlertView mAlertView;

    public static AlertViewFactory getInstance() {
        if (defaultInstance == null) {
            synchronized (AlertViewFactory.class) {
                if (defaultInstance == null) {
                    defaultInstance = new AlertViewFactory();
                }
            }
        }
        return defaultInstance;
    }

    private AlertViewFactory() {
    }

    public AlertView getAlertView() {
        return mAlertView;
    }

    /**
     * 性别选择
     */
    public AlertView getGenderAlertView(final Context context, OnItemClickListener onItemClickListener) {
        mAlertView = null;
        mAlertView = new AlertView(null, null, context.getResources().getString(R.string.cancel),
                null, context.getResources().getStringArray(R.array.gender), context,
                AlertView.Style.ActionSheet, onItemClickListener).setCancelable(true);
        return mAlertView;
    }

    /**
     * 图片类型选择
     */
    public AlertView getPhotoTypeAlertView(final Context context, OnItemClickListener onItemClickListener) {
        mAlertView = null;
        mAlertView = new AlertView(null, null, context.getResources().getString(R.string.cancel),
                null, context.getResources().getStringArray(R.array.photo_type), context,
                AlertView.Style.ActionSheet, onItemClickListener).setCancelable(true);
        return mAlertView;
    }


    /**
     * 检测更新apk alert
     */
    public AlertView getUpdateApkAlert(final Context context, OnItemClickListener onItemClickListener) {
        mAlertView = null;
        mAlertView = new AlertView(null, context.getString(R.string.app_update),
                context.getString(R.string.cancel), new String[]{context.getString(R.string.determine)},
                null, context, AlertView.Style.Alert, onItemClickListener).setCancelable(true);
        return mAlertView;
    }


    public AlertView getContentAlert(final Context context,String title,String content, OnItemClickListener onItemClickListener) {
        mAlertView = null;
        mAlertView = new AlertView(title, content,
                context.getString(R.string.cancel), new String[]{context.getString(R.string.btn_sure)},
                null, context, AlertView.Style.Alert, onItemClickListener).setCancelable(true);
        return mAlertView;
    }

    /**
     * 拨打电话
     */
    public AlertView getCallAlert(final Context context, final String tel) {
        mAlertView = null;
        mAlertView = new AlertView(null, context.getString(R.string.call_num, tel), context.getResources().getString(R.string.cancel),
                new String[]{context.getResources().getString(R.string.determine)}, null, context,
                AlertView.Style.Alert, new OnItemClickListener() {
            @Override
            public void onItemClick(Object o, int position) {
                if (position == 0 && !TextUtils.isEmpty(tel)) {
                    ViewUtils.call(context, tel);
                }
            }
        }).setCancelable(true);
        return mAlertView;
    }

    /**
     * 清空缓存提示
     */
    public AlertView getCacheAlert(final Context context, OnItemClickListener onItemClickListener) {
        mAlertView = null;
        mAlertView = new AlertView(context.getString(R.string.clean_cache), context.getString(R.string.clean_cache_hint),
                context.getString(R.string.cancel), new String[]{context.getString(R.string.determine)},
                null, context, AlertView.Style.Alert, onItemClickListener).setCancelable(true);
        return mAlertView;
    }

    /**
     * 是否放弃支付订单
     */
    public AlertView getCancelOrderAlert(final Context context, OnItemClickListener onItemClickListener) {
        mAlertView = null;
        mAlertView = new AlertView(null, context.getString(R.string.sure_cancel_order_hint),
                context.getString(R.string.cancel_order), new String[]{context.getString(R.string.continue_order)},
                null, context, AlertView.Style.Alert, onItemClickListener).setCancelable(true);
        return mAlertView;
    }


}
